<?php

include_once ( "AbstractDAO.php" );

class RecommendDAO extends AbstractDAO 
{
	function GetRecommendB2CShopByUid($uid, $count='4')
	{
		$sql="select b2cshops from recommend_b2cshop where user_id=$uid or user_id=0";
		$id_list=$this->db->GetValue($sql);
		if($id_list==false)
			return false;
		else
		{
			$sql="select si.id, si.shop_name, si.plat_id, sp.plat_name, si.logo_url 
			from shop_info si, shop_platform sp where si.id in ($id_list) and si.plat_id=sp.id 
			order by RAND() limit 0, $count";
			return $this->db->GetPlan($sql);
		}
	}
	
	function GetRecommendC2CshopByUid($uid, $count='8')
	{
		$sql="select c2cshops from recommend_c2cshop where user_id=$uid or user_id=0";
		$id_list=$this->db->GetValue($sql);
		if($id_list==false)
			return false;
		else
		{
			$sql="select si.id, si.shop_name, si.plat_id, sp.plat_name, si.logo_url 
			from shop_info si, shop_platform sp where si.id in ($id_list) and si.plat_id=sp.id 
			order by RAND() limit 0, $count";
			return $this->db->GetPlan($sql);
		}
	}
	
	function GetRecommendReviewByUid($uid, $count='5')
	{
		$sql="select review_id from recommend_review where user_id=$uid or user_id=0";
		$id_list=$this->db->GetValue($sql);
		if($id_list==false)
			return false;
		else
		{
			$sql="select r.id as rid, ubi.id as uid, ubi.nick, ubi.logo_path, si.id as sid, si.shop_name,si.logo_url, sp.id as plat_id, sp.plat_name, r.review_date, r.score, r.reality, r.service, r.velocity, r.rate,r.content, r.response_count 
			from review r, user_basic_info ubi, shop_info si, shop_platform sp where r.id in ($id_list) and r.user_id=ubi.id and r.shop_id=si.id and si.plat_id=sp.id 
			order by RAND() limit 0, $count";
			return $this->db->GetPlan($sql);
		}
	}
	
	function GetRecommendProductByUid($uid, $count='5')
	{
		
		$sql="select products from recommend_product where user_id=$uid or user_id=0";
		$id_list=$this->db->GetValue($sql);
		if($id_list==false)
			return false;
		else
		{
			$sql="select pi.id, pi.product_name, pi.pic_path from product_info pi where pi.id in ($id_list)
			order by RAND() limit 0, $count";
			return $this->db->GetPlan($sql);
		}
		
	}
	
	function GetRecommendListByUid($uid, $count='5')
	{
	}
	
	
}
